
import java.net.Socket;
import java.net.ServerSocket;
import java.io.*;



public class Server {
	private ServerSocket serverSock;
	private DataStorer dataSaver;

	public Server(int serverPort) {
		try {
			serverSock = new ServerSocket(serverPort);
			dataSaver = new DataStorer();			
		}
		catch (IOException e){
			e.printStackTrace(System.err);
		}
	}


	public void waitForConnections() {

		while (true) {
			try {
				Socket sock = null;

			//	System.out.println("Waiting for a new connection.");
				sock = serverSock.accept();
			//	System.out.println("Have accepted new socket.");
				
				new ClientHandler(sock, System.currentTimeMillis(), dataSaver);						
			}
			catch (IOException e){
				e.printStackTrace(System.err);
			}


		//	System.err.println("Finished starting thread...");
		}
	}


	public static void main(String argv[]) {
		int port = 1234;
		Server server = new Server(port);
		server.waitForConnections();
	}
}